Importing and Plotting a CSV with latitude/longitude columns

First, we'll be loading and plotting Natural Earth's Populated Places dataset, in CSV format.

With GeoPandas

In [1]:
import pandas as pd
import geopandas as gpd

from shapely.geometry import Point

%matplotlib inline
In [2]:
df = pd.read_csv('data/ne_populated_places.csv')
gdf = gpd.GeoDataFrame(
    df,
    geometry=df.apply(lambda row: Point(row['longitude'], row['latitude']),axis=1),
    crs=4326
)

gdf.plot()
Out[2]:
<matplotlib.axes._subplots.AxesSubplot at 0x122e1fed0>

With CARTOFrames

In [3]:
from cartoframes.data import Dataset
from cartoframes.viz import Map, Layer
In [4]:
df = pd.read_csv('data/ne_populated_places.csv')
Map(Layer(Dataset(df)))
Out[4]:

Importing and plotting a GeoPackage

Next, we'll load a GeoPackage of Natural Earth's countries dataset.

With GeoPandas

In [5]:
gdf = gpd.read_file('data/ne_countries.gpkg')
gdf.plot()
Out[5]:
<matplotlib.axes._subplots.AxesSubplot at 0x120c84490>

With GeoPandas and CARTOFrames.

We'll add a popup to the Layer to show the country's name.

In [6]:
gdf = gpd.read_file('data/ne_countries.gpkg')
Map(
    Layer(
        Dataset(gdf),
        popup={'hover': '$NAME'}
    )
)
Out[6]: